<?php
class Zend_Validate_NameValidator extends Zend_Validate_Abstract
{

    protected $minimum = 4;
    protected $maximum = 16;

    const INVALID		= 'regexInvalid';
    const NOT_MATCH		= 'regexNotMatch';
    const ERROROUS		= 'regexErrorous';
	const STRINGSHORT	='stringShort';
	const STRINGLONG	='stringLong';

 protected $_messageTemplates = array(
        self::INVALID		=> "String contains invalid characters",
        self::NOT_MATCH 	=> "Does not match against pattern '%pattern%'",
        self::ERROROUS		=> "There was an internal error while using the pattern '%pattern%'",
		self::STRINGLONG	=>   "'%value%' is more than %max% characters long",
		self::STRINGSHORT	=> "'%value%' is less than %min% characters long"
    );

protected $_messageVariables = array(
		'min' 	=> 'minimum',
		'max' 	=> 'maximum'
		);

	public function isValid($value)
    {
		$length = mb_strlen($value);
		$this->_setValue($value);
		
		//if(preg_match("/^[0-9!@#$%^&*()+\|?\\\.\/\[\]\'\"`~={}:;]+$/",$value)) //|| preg_match("/^[!@#$%^&*()+\|?\\\.\/\[\]\'\"`~={}:;]+$/",$value))
		//{
		//$this->_error(self::INVALID);
		//return false;
		//}
		if(!preg_match("/^[^\d !@#$%^&*()+\|?\\\.\/\[\]\'\"`~={}:;]+[a-zа-яё]+[а-яё\w]+$/iu",$value) && $length > $this->minimum || preg_match("/^[0-9!@#$%^&*()+\|?\\\.\/\[\]\'\"`~={}:;]+$/",$value) )
		{
		$this->_error(self::INVALID);
		return false;
		}
		
		if($length > $this->maximum)
		{
		$this->_error(self::STRINGLONG);
		return false;
		}

		if($length < $this->minimum)
		{
		$this->_error(self::STRINGSHORT);
		return false;
		}
		return true;
	
	}
}
